package com.xlobo.api.inventory.testcase;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.xlobo.api.inventory.parameter.InventoryFreezeBean;
import com.xlobo.api.inventory.parameter.InventoryFreezeProductInfoBean;
import com.xlobo.api.inventory.service.InventoryFreezeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.Inventory;
import com.ymttest.database.sqlwapper.InventoryWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 库存冻结 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_InventoryFreeze {
	private static InventoryFreezeBean freezeBean;
	private static InventoryFreezeCall freezeCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("库存冻结");
	}

	@Before
	public void caseUp() {
		freezeBean = new InventoryFreezeBean();
		freezeCall = new InventoryFreezeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(freezeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_InventoryFreeze_001() {
		Logger.start(true,"库存冻结用成功");
		try {
			String guid = TestDataManager.getRandomUUID().toString();
			InventoryWapper iw = new InventoryWapper();
			List<Inventory> InventoryList = iw.getTop10InventoryInfo();
			Random r = new Random();
			int index = r.nextInt(10);
			String skucode = InventoryList.get(index).getSkucode();
			Integer logisticId = InventoryList.get(index).getLogisticid();
			String userid = InventoryList.get(index).getUserid();
			ArrayList<InventoryFreezeProductInfoBean> productList = new ArrayList<InventoryFreezeProductInfoBean>();
			InventoryFreezeProductInfoBean productinfo = new InventoryFreezeProductInfoBean();
			productinfo.setSkucode(skucode);
			productinfo.setFreezeCount(2);
			productList.add(productinfo);
			freezeBean.setLogisticId(logisticId);
			freezeBean.setProductInfos(productList);
			freezeBean.setBusinessId(guid);
			freezeBean.setBusinessType(111);
			freezeBean.setComment("备注");
			freezeBean.setUserId(userid);
			freezeCall.setData(freezeBean);
			freezeCall.callService();
			Logger.comment("发送appcall报文:" + freezeCall.getEntityString());
			Logger.comment("返回appcall报文：" + freezeCall.getReturnData());
			Logger.verifyEquals("true", freezeCall.getSuccess(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_InventoryFreeze_002() {
		Logger.start(true,"不输入必填项ProductInfos失败");
		try {
			// TODO 补全case代码
			org.junit.Assert.fail();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_InventoryFreeze_003() {
		Logger.start(true,"不输入必填项LogisticId失败");
		try {
			// TODO 补全case代码
			org.junit.Assert.fail();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}